import React from 'react';
import $ from 'jquery';
require('../../css/btn-bar');

export default class BtnBarSwitch extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            stateType: 0,
            stateCur:this.props.stateTxt[0]
        };
        this.handleClick = this.handleClick.bind(this)
    }
    static propTypes = {
        stateTxt: React.PropTypes.array.isRequired,
        btnType: React.PropTypes.string.isRequired
    };
    handleClick(){
        let typeLen = this.props.stateTxt.length,
            typeCur = this.state.stateType;
        if(this.state.stateType < (typeLen - 1)){
            this.setState({
                stateType:++typeCur,
                stateCur:this.props.stateTxt[typeCur]
            })
        }else{
            this.setState({
                stateType:0,
                stateCur:this.props.stateTxt[0]
            });
            typeCur = 0
        }
        this.props.onSwitch(typeCur)
    }
    render(){
        return (
            <div className="btn-bar-switch" onClick={this.handleClick}>
                <span>{this.state.stateCur}</span>
            </div>
        )
    }
}